package com.xiaomazi.edu.controller.front;

import com.xiaomazi.common.utils.JwtUtils;
import com.xiaomazi.common.utils.R;
import com.xiaomazi.edu.dto.front.CourseFrontDTO;
import com.xiaomazi.edu.service.CourseService;
import com.xiaomazi.servicebase.entity.CourseInfoToOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: llxy-parent
 * @description: 课程前端控制器
 * @author: 小马子
 * @create: 2023-03-02 15:32
 **/
@RestController
@RequestMapping("/eduservice/courseFront")
public class CourseFrontController {

    @Autowired
    private CourseService courseService;

    @PostMapping("/getCourseList")
    public R getCourseList(@RequestBody CourseFrontDTO courseFrontDTO){
        return courseService.getCourseList(courseFrontDTO);
    }

    @GetMapping("/getCourseByCourseId/{courseId}")
    public R getCourseInfoById(@PathVariable String courseId,
                               HttpServletRequest request){
        return courseService.getCourseByCourseId(courseId, JwtUtils.getMemberIdByJwtToken(request));
    }

    @GetMapping("/getCourseToOrderByCourseId/{courseId}")
    public CourseInfoToOrder getCourseToOrderByCourseId(@PathVariable String courseId){
        return courseService.getCourseToOrderByCourseId(courseId);
    }
}
